<?php
namespace Partner\Model;

class ProductCategoryModel extends CommonTreeModel {
	
	// 栏目类型
	public $types = array(
			'page' => '单页图文栏目',
			'list' => '商品列表栏目',
			'url' => '外部链接栏目',
	);
	
	protected $_auto = array(
			array('content', 'getContent', self::MODEL_BOTH, 'callback'),
			array('tpl_config', 'getTplConfig', self::MODEL_BOTH, 'callback'),
	);
	
	// 插入成功后的回调方法
	protected function _after_insert($data, $options) {
		/*设置路径*/
		$newId = $data['id'];
		$pid = $data['pid']*1;
		$path = "$pid";
		while( $pid != 0 ) {
			$productCategory = M("ProductCategory")->where('id=%d', $pid)->find();
			$pid = $productCategory['pid']*1;
			$path = $pid.",{$path}";
		}
		$path.=",$newId";
		M("ProductCategory")->where('id=%d', $newId)->setField('path', $path);
	}
	
	/**
	 * 获得单页内容
	 */
	public function getContent() {
		if( !isset( $_REQUEST['content']) ) return false;
		$content = I("content", '', 'htmlspecialchars_decode');
		return $content;
	}
	
	/**
	 * 获得模板配置
	 */
	public function getTplConfig() {
		if( !isset( $_REQUEST['tpl_config']) ) return false;
		$tpl_config = I("tpl_config");
		return serialize( $tpl_config );
	}
	
}